{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5c864795",
   "metadata": {},
   "source": [
    "## 1. 类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9b3ce394",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Cat:\n",
    "    '这是一个猫类，帮助文档'\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "    def eat(self):\n",
    "        print(self.name + '吃吃吃')\n",
    "    def drink(self):\n",
    "        print(self.name + '喝喝喝')\n",
    "    def sleep(self):\n",
    "        # print(self.name + '睡觉觉')\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "856e0a18",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xiaoxiao\n",
      "xiaoxiao吃吃吃\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "mao = Cat('xiaoxiao')\n",
    "print(mao.name)\n",
    "mao.eat()\n",
    "print(mao.sleep())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "312987f2",
   "metadata": {},
   "source": [
    "### 1.1 mao.\\_\\_doc\\_\\_——帮助文档"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8a3e7d12",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'这是一个猫类，帮助文档'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mao.__doc__"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b79f224f",
   "metadata": {},
   "source": [
    "### 1.2重载运算符\n",
    "def __add__(self, v2): 加    \n",
    "def __sub__(self, v2): 减   \n",
    "def __mul__(self, v2): 乘  \n",
    "def __str__(self): 使用print   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "06396177",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(isinstance(mao, Cat))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36eae4f1",
   "metadata": {},
   "source": [
    "## 2. 继承"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3e9bd75f",
   "metadata": {},
   "outputs": [],
   "source": [
    "class xiaoMao(Cat):\n",
    "    def __init__(self,name,age,sex, color):\n",
    "        super().__init__(age)\n",
    "        self.name = name\n",
    "        self.sex = sex\n",
    "        self.__color = color\n",
    "    def get_color(self):\n",
    "        return self.__color"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3aa3259b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaa吃吃吃\n",
      "red\n"
     ]
    }
   ],
   "source": [
    "x1 = xiaoMao('aaa', 18, '男', 'red')\n",
    "x1.eat()\n",
    "print(x1.get_color())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47854694",
   "metadata": {},
   "source": [
    "## 3. 注意释放空间——del"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2a0c2e5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "del x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78c957cf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mining",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
